import { FormType } from '@/base-ui/base-form/type'
import { IModalConfig } from '@/components/page-modal/type'
import { ActionDesc } from '@/global/constant'

const getCustomRuleModalAddOrEdit = (isAdd = true): IModalConfig => {
  const config: IModalConfig = {
    modalProps: {
      title: isAdd ? '新增规则' : '编辑规则',
      width: 400,
      maskClosable: false,
      closable: false
    },
    formProps: {
      desc: isAdd ? ActionDesc.Add : ActionDesc.Edit,
      layout: { span: 24 },
      formConfig: {
        name: isAdd ? 'custom-rule-add' : 'custom-rule-edit',
        size: 'small',
        labelAlign: 'right',
        // labelCol: 输入框这些前面的文字的宽度
        labelCol: { flex: '85px' },
        // labelWrap：表单前面的label宽度(labelCol指定的flex)不够,那么他会进行自动换行
        // labelWrap: true,
        // wrapperCol: { flex: 1 },
        colon: false
        // style: { minWidth: 700 }
      },
      itemsConfig: [
        {
          type: FormType.Input,
          prop: 'targetName',
          name: 'targetName',
          label: '敏感词',
          rules: isAdd ? [{ required: true }] : [],
          input: {
            placeholder: '请输入敏感词'
          }
        },
        {
          type: FormType.Input,
          prop: 'replaceName',
          name: 'replaceName',
          label: '替换词',
          rules: isAdd ? [{ required: true }] : [],
          input: {
            placeholder: '请输入替换词'
          }
        },
        {
          type: FormType.Radio,
          prop: 'isOpen',
          name: 'isOpen',
          label: '状态',
          rules: isAdd ? [{ required: true }] : [],
          radio: {
            options: [
              { value: 1, content: '启用' },
              { value: 0, content: '关闭' }
            ]
          }
        }
      ]
    }
  }

  return config as IModalConfig
}

export default getCustomRuleModalAddOrEdit
